\chapter{master\+\_\+process }
\hypertarget{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2modules_2master__machine_2master__process}{}\label{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2modules_2master__machine_2master__process}\index{master\_process@{master\_process}}
\label{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2modules_2master__machine_2master__process_autotoc_md55}%
\Hypertarget{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2modules_2master__machine_2master__process_autotoc_md55}%




\href{mailto:neozng1@hnu.edu.cn}{\texttt{neozng1@hnu.\+edu.\+cn}}

\begin{quote}
TODO\+:


\begin{DoxyEnumerate}
\item 补全标志位解析和发送设置的代码
\item 增加发送给视觉数据的时间戳用于数据对齐 
\end{DoxyEnumerate}\end{quote}
\hypertarget{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2modules_2master__machine_2master__process_autotoc_md56}{}\doxysection{\texorpdfstring{总览和封装说明}{总览和封装说明}}\label{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2modules_2master__machine_2master__process_autotoc_md56}
模块包含了和视觉通信的初始化、向上位机发送信息的接口和模块的串口的回调处理。接口的定义统一，可以方便的替换成其他通信方式，如\+CAN。\hypertarget{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2modules_2master__machine_2master__process_autotoc_md57}{}\doxysection{\texorpdfstring{代码结构}{代码结构}}\label{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2modules_2master__machine_2master__process_autotoc_md57}
.h文件内包括了外部接口和与\texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*}视觉上位机通信的数据结构定义\texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*}，以及模块对应的宏。c文件内为私有函数和外部接口的定义。

本模块主要是对协议解析的处理和协议发送的封装，实际内容不多。协议相关内容都在{\ttfamily \doxylink{seasky__protocol_8h_source}{seasky\+\_\+protocol.\+h}}中。\hypertarget{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2modules_2master__machine_2master__process_autotoc_md58}{}\doxysection{\texorpdfstring{类型定义}{类型定义}}\label{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2modules_2master__machine_2master__process_autotoc_md58}
和视觉通信所必须的标志位和数据。包括开火模式，目标状态，目标类型，接收/发送数据结构体。


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{typedef}\ \textcolor{keyword}{enum}}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ NO\_FIRE\ =\ 0,}
\DoxyCodeLine{\ \ \ \ AUTO\_FIRE\ =\ 1,}
\DoxyCodeLine{\ \ \ \ AUTO\_AIM\ =\ 2}
\DoxyCodeLine{\}\ Fire\_Mode\_e;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{typedef}\ \textcolor{keyword}{enum}}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ NO\_TARGET\ =\ 0,}
\DoxyCodeLine{\ \ \ \ TARGET\_CONVERGING\ =\ 1,}
\DoxyCodeLine{\ \ \ \ READY\_TO\_FIRE\ =\ 2}
\DoxyCodeLine{\}\ Target\_State\_e;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{typedef}\ \textcolor{keyword}{enum}}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ NO\_TARGET\_NUM\ =\ 0,}
\DoxyCodeLine{\ \ \ \ HERO1\ =\ 1,}
\DoxyCodeLine{\ \ \ \ ENGINEER2\ =\ 2,}
\DoxyCodeLine{\ \ \ \ INFANTRY3\ =\ 3,}
\DoxyCodeLine{\ \ \ \ INFANTRY4\ =\ 4,}
\DoxyCodeLine{\ \ \ \ INFANTRY5\ =\ 5,}
\DoxyCodeLine{\ \ \ \ OUTPOST\ =\ 6,}
\DoxyCodeLine{\ \ \ \ SENTRY\ =\ 7,}
\DoxyCodeLine{\ \ \ \ BASE\ =\ 8}
\DoxyCodeLine{\}\ Target\_Type\_e;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{typedef}\ \textcolor{keyword}{struct}}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ Fire\_Mode\_e\ fire\_mode;}
\DoxyCodeLine{\ \ \ \ Target\_State\_e\ target\_state;}
\DoxyCodeLine{\ \ \ \ Target\_Type\_e\ target\_type;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordtype}{float}\ pitch;}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordtype}{float}\ yaw;}
\DoxyCodeLine{\}\ \mbox{\hyperlink{struct_vision___recv__s}{Vision\_Recv\_s}};}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{typedef}\ \textcolor{keyword}{enum}}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ BLUE\ =\ 0,}
\DoxyCodeLine{\ \ \ \ RED\ =\ 1}
\DoxyCodeLine{\}\ Enemy\_Color\_e;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{typedef}\ \textcolor{keyword}{enum}}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ MODE\_AIM\ =\ 0,}
\DoxyCodeLine{\ \ \ \ MODE\_SMALL\_BUFF\ =\ 1,}
\DoxyCodeLine{\ \ \ \ MODE\_BIG\_BUFF\ =\ 2}
\DoxyCodeLine{\}\ Work\_Mode\_e;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{typedef}\ \textcolor{keyword}{enum}}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ BIG\_AMU\_10\ =\ 10,}
\DoxyCodeLine{\ \ \ \ SMALL\_AMU\_15\ =\ 15,}
\DoxyCodeLine{\ \ \ \ BIG\_AMU\_16\ =\ 16,}
\DoxyCodeLine{\ \ \ \ SMALL\_AMU\_18\ =\ 18,}
\DoxyCodeLine{\ \ \ \ SMALL\_AMU\_30\ =\ 30,}
\DoxyCodeLine{\}\ Bullet\_Speed\_e;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{typedef}\ \textcolor{keyword}{struct}}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ Enemy\_Color\_e\ enemy\_color;}
\DoxyCodeLine{\ \ \ \ Work\_Mode\_e\ work\_mode;}
\DoxyCodeLine{\ \ \ \ Bullet\_Speed\_e\ bullet\_speed;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordtype}{float}\ yaw;}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordtype}{float}\ pitch;}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordtype}{float}\ roll;}
\DoxyCodeLine{\}\ \mbox{\hyperlink{struct_vision___send__s}{Vision\_Send\_s}};}

\end{DoxyCode}
\hypertarget{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2modules_2master__machine_2master__process_autotoc_md59}{}\doxysection{\texorpdfstring{外部接口}{外部接口}}\label{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2modules_2master__machine_2master__process_autotoc_md59}

\begin{DoxyCode}{0}
\DoxyCodeLine{\mbox{\hyperlink{struct_vision___recv__s}{Vision\_Recv\_s}}\ *VisionInit(\mbox{\hyperlink{group___u_a_r_t___exported___types_ga5de4a49eb132735325e706f406c69d6e}{UART\_HandleTypeDef}}\ *\_handle);}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{void}\ VisionSend(\mbox{\hyperlink{struct_vision___send__s}{Vision\_Send\_s}}\ *send);}

\end{DoxyCode}


给{\ttfamily Vision\+Init()}传入串口handle，将初始化一个视觉通信模块，返回值是接收数据的结构体指针。拥有视觉模块的应用应该在初始化中调用此函数，并保存返回值的指针。

调用{\ttfamily Vision\+Send}并传入填好发送数据的结构体，会通过底层的通信模块向视觉发送一帧报文。\hypertarget{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2modules_2master__machine_2master__process_autotoc_md60}{}\doxysection{\texorpdfstring{私有函数和变量}{私有函数和变量}}\label{md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2modules_2master__machine_2master__process_autotoc_md60}

\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{struct_vision___recv__s}{Vision\_Recv\_s}}\ recv\_data;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ usart\_instance\ *vision\_usart\_instance;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ DecodeVision()}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{static}\ uint16\_t\ flag\_register;}
\DoxyCodeLine{\ \ \ \ get\_protocol\_info(vision\_usart\_instance-\/>recv\_buff,\ \&flag\_register,\ (uint8\_t*)\&recv\_data.pitch);}
\DoxyCodeLine{\ \ \ \ \textcolor{comment}{//\ TODO:\ code\ to\ resolve\ flag\_register;}}
\DoxyCodeLine{\}}

\end{DoxyCode}


第一个是保存接收数据的结构体，其指针将会在初始化的时候返回给拥有者。目前最多只能配置一个视觉模块。

第二个是该模块拥有的串口实例指针，用于调度其底层的发送和接收。如果要换成\+CAN/\+SPI等，替换成对应实例，并修改初始化和发送的实现即可。

{\ttfamily Decode\+Vision()}是解析视觉接收数据的回调函数，会在串口接收回调中被调用。如果修改通信协议，只需要更改

{\ttfamily get\+\_\+protocol\+\_\+info()}。 